package com.example.aboutwork.tests;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class TestWrapper {

    @Test
    public void testLong() {
        int repeats = 40000000;
        long time;

        time = System.currentTimeMillis();
        long counterA = 0L;
        for (int i = 0; i < repeats; i++) {
            counterA = counterA + 4L;
        }
        System.out.println(counterA + " A: " + (System.currentTimeMillis() - time) + " ms");

        time = System.currentTimeMillis();
        Long counterB = 0L;
        for (int i = 0; i < repeats; i++) {
            counterB = counterB + 4L;
        }
        System.out.println(counterB + " B: " + (System.currentTimeMillis() - time) + " ms");

    }


    @Test
    public void testValue() {
        int repeats = 1000000;

        List<String> numbers = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            numbers.add(String.valueOf(i));
        }

        long time;

        time = System.currentTimeMillis();
        long sumOfLongsA = 0L;
        for (int i = 0; i < repeats; i++) {
            for (String number : numbers) {
                sumOfLongsA += Long.parseLong(number);
            }
        }
        System.out.println(sumOfLongsA + " Parse: " + (System.currentTimeMillis() - time) + " ms");

        time = System.currentTimeMillis();
        long sumOfLongsB = 0L;
        for (int i = 0; i < repeats; i++) {
            for (String number : numbers) {
                sumOfLongsB += Long.valueOf(number);
            }
        }
        System.out.println(sumOfLongsB + " value: " + (System.currentTimeMillis() - time) + " ms");
    }
}
